package com.fitso.model.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;

public class Contact extends ModelBean implements Comparable<Contact>, Serializable {
	// Only change on breaking changes, i.e., removing fields
	private static final long serialVersionUID = 1L;
	
	private Address _address;
	private String _firstName, _lastName;
	private List<Phone> _phones;

	public Contact() {}

	public void addPhone(Phone phone) {
		if (_phones == null) {
			_phones = new ArrayList<Phone>();
		}
		_phones.add(phone);
	}

	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (o == this) {
			return true;
		}
		if (o.getClass() != getClass()) {
			return false;
		}

		Contact other = (Contact) o;
		return new EqualsBuilder().append(_address, other._address).append(_firstName, other._firstName).append(
				_lastName, other._lastName).append(_phones, other._phones).isEquals();
	}

	public Address getAddress() {
		return _address;
	}

	public String getFirstName() {
		return _firstName;
	}

	public String getLastName() {
		return _lastName;
	}

	public List<Phone> getPhones() {
		return _phones;
	}

	public int hashCode() {
		return new HashCodeBuilder().append(_address).append(_firstName).append(_lastName).append(_phones).toHashCode();
	}

	public void setAddress(Address address) {
		_address = address;
	}

	public void setFirstName(String firstName) {
		_firstName = firstName;
	}

	public void setLastName(String lastName) {
		_lastName = lastName;
	}

	public void setPhones(List<Phone> phones) {
		_phones = phones;
	}

	public String toString() {
		return new ReflectionToStringBuilder(this).toString();
	}

	public int compareTo(Contact other) {
		return new CompareToBuilder().append(_lastName, other._lastName).append(_firstName, other._firstName).append(
				_address, other._address).append(_phones, other._phones).toComparison();
	}
}
